package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.BrandCategoryAddNewDTO;
import cn.tedu.csmall.product.service.IBrandCategoryService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 处理品牌类别相关的请求
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Api(tags = "06.品牌类别管理模块")
@Slf4j
@Validated
@RequestMapping("/brandCategories")
@RestController
public class BrandCategoryController {
    @Autowired
    private IBrandCategoryService brandCategoryService;
    public BrandCategoryController(){
        log.debug("创建控制器对象: BrandCategoryController");
    }
    //http://localhost:9080/brandCategories/addnewbc?brandId=101&categoryId=101
    @ApiOperation("添加品牌类别")
    @ApiOperationSupport(order = 1)
    @PostMapping("/addnewbc")
    //                       ↓↓↓↓↓↓以下是新添加的注解
    public JsonResult<Void> addNew(@Valid BrandCategoryAddNewDTO brandCategoryAddNewDTO){
        log.debug("开始处理[添加品牌类别]的请求,参数:{}",brandCategoryAddNewDTO);
        brandCategoryService.addNew(brandCategoryAddNewDTO);
        log.debug("测试添加数据成功!");
        return JsonResult.ok();

    }
    //http://localhost:9080/brandCategories/9527/delete
    @ApiOperation("根据id删除品牌类别")
    @ApiOperationSupport(order = 2)
    @PostMapping( "/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@Range(min = 1,message = "删除品牌类别失败，尝试删除的品牌类别的ID无效！")
                                   @PathVariable Long brandId,Long categoryId){
        log.debug("开始处理[根据id删除品牌类别]的请求,参数: {},{}", brandId,categoryId);
        brandCategoryService.delete(brandId,categoryId);
        return JsonResult.ok();
    }

}
